package com.he.fetch.test.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Subject @author Abhai Raj
 */
@Entity
@Table(name = "TXN")
public class Txn implements java.io.Serializable {

    private static final long serialVersionUID = -2815306582571382192L;

    @ManyToOne
    @JoinColumn(name = "ACCOUNT_ID", nullable = false)
    private Account account;

    @Column(name = "AMOUNT", nullable = false)
    private Double amount;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "DATE", nullable = false)
    private Date date;

    @Column(name = "DESCRIPTION", nullable = false, length = 255)
    private String description;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID", unique = true, nullable = false)
    private Integer id;

    @Override
    public boolean equals(Object obj) {
	if (this == obj) {
	    return true;
	}
	if (obj == null) {
	    return false;
	}
	if (!(obj instanceof Txn)) {
	    return false;
	}
	Txn other = (Txn) obj;
	if (this.account == null) {
	    if (other.account != null) {
		return false;
	    }
	} else if (!this.account.equals(other.account)) {
	    return false;
	}
	if (this.description == null) {
	    if (other.description != null) {
		return false;
	    }
	} else if (!this.description.equals(other.description)) {
	    return false;
	}
	return true;
    }

    public Account getAccount() {
	return this.account;
    }

    public Double getAmount() {
	return this.amount;
    }

    public Date getDate() {
	return this.date;
    }

    public String getDescription() {
	return this.description;
    }

    public Integer getId() {
	return this.id;
    }

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result
		+ (this.account == null ? 0 : this.account.hashCode());
	result = prime * result
		+ (this.description == null ? 0 : this.description.hashCode());
	return result;
    }

    public void setAccount(Account account) {
	this.account = account;
    }

    public void setAmount(Double amount) {
	this.amount = amount;
    }

    public void setDate(Date date) {
	this.date = date;
    }

    public void setDescription(String description) {
	this.description = description;
    }

    public void setId(Integer id) {
	this.id = id;
    }

    @Override
    public String toString() {
	return "[id=" + this.id + ",description=" + this.description
		+ ",amount=" + this.amount + "]";
    }

}